﻿using Google.Protobuf.WellKnownTypes;
using System;
using UnityEngine;
using UnityEngine.UI;

public class CommentInput : MonoBehaviour
{
    public InputField inputField;

    public Action<string> onInputEnd;
    public Action<string> onSend;

    public Button sendBtn;

    public Color activeColor = Color.white;
    public Color disactiveColor = Color.white;

    void Awake()
    {
        inputField.onValueChanged.AddListener(this.OnInput);
        RefreshSendBtn();
    }

    private void OnInput(string value)
    {
        RefreshSendBtn();

    }

    void RefreshSendBtn()
    {
        if (inputField.text.Length > 0)
        {
            this.sendBtn.interactable = true;
            this.sendBtn.GetComponent<Image>().color = activeColor;
        }
        else
        {
            this.sendBtn.interactable = false;
            this.sendBtn.GetComponent<Image>().color = disactiveColor;
        }
    }

    public void OnClickClose()
    {
        this.onInputEnd?.Invoke(this.inputField.text);
    }

    public void OnClickSend()
    {
        this.onSend?.Invoke(this.inputField.text);
    }
}
